//
//  MapViewController.m
//  chanyou
//
//  Created by wanli on 15/1/6.
//  Copyright (c) 2015年 wanli. All rights reserved.
//

#import "MapViewController.h"
#import "MapAnnotation.h"
@interface MapViewController ()

@end

@implementation MapViewController

- (void)dealloc
{
    [_name_zh_cn release];
    [_mapView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _mapView.mapType = MKMapTypeStandard;
    _mapView.delegate = self;
 
    CLLocationCoordinate2D myLocation = {_lat,_lng};
    MapAnnotation *annotation = [[MapAnnotation alloc] initWithCoordinate:myLocation];
    annotation.title = _name_zh_cn;

    [_mapView addAnnotation:annotation];
    [annotation release];
 
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(myLocation,2500, 2500);
    MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:viewRegion];//适配map view的尺寸
    [_mapView setRegion:adjustedRegion animated:YES];
    
    [self.view addSubview:_mapView];
    [_mapView release];
    
    CLLocationManager *locationManager = [[[CLLocationManager alloc] init] autorelease];
    
    if (![CLLocationManager locationServicesEnabled]) {
        NSLog(@"不能使用定位功能");
    }else{
        
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        //    locationManager.distanceFilter = 1;
        locationManager.delegate = self;
        [locationManager startUpdatingLocation];
        
    }
    
    
}

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
//    mapView.mapType = MKMapTypeSatellite;
    MKPinAnnotationView *first = [views lastObject];
    first.animatesDrop = YES;
    first.pinColor = MKPinAnnotationColorPurple;
    UIImage *im = [UIImage imageNamed:@"地图坐标"];
    first.image = im;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
